package com.dt76.smallloanfrontendservice.service.etao.impl;

import com.dt76.smallloanfrontendservice.mapper.etao.UserMapper;
import com.dt76.smallloanfrontendservice.pojo.etao.User;
import com.dt76.smallloanfrontendservice.service.etao.UserService;
import com.dt76.smallloanfrontendservice.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Result findUserByLogin(String userName, String password) {
        Result result = new Result();
        User user = userMapper.findUserByLogin(userName, password);
        if (user != null) {
            result.setCurrentUser(user);
            result.setSuccess(true);
        } else {
            result.setSuccess(false);
        }
        return result;
    }


    @Override
    public Result findUserByEmail(String email) {
        Result result = new Result();
        User user = userMapper.findUserByEmail(email);
        if (user != null) {
            result.setCurrentUser(user);
            result.setSuccess(true);
        } else {
            result.setSuccess(false);
        }
        return result;
    }

    @Override
    public boolean addUser(User user) {
        boolean fg = false;
        if (userMapper.saveUser(user) == 1) {
            fg = true;
        }
        return fg;
    }


}
